package com.bawei.yuekao.fragment;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bawei.yuekao.R;

import java.util.Timer;
import java.util.TimerTask;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class WelcomeFragmentThree extends Fragment {
    private TextView textView;
    private Timer timer;
    private int position = 5;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what == 101){
                textView.setText("倒计时"+position--);
                if(position == 0){
                    timer.cancel();
                }
            }
        }
    };


    public WelcomeFragmentThree() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_welcome_fragment_three, container, false);
        textView= view.findViewById(R.id.tv);
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(101);

            }
        },0,1000);
        return view;
    }

}
